package com.acme.bankapp.domain.bank.account;

import com.acme.bankapp.service.bank.exception.NotEnoughFundsException;

/**
 * 
 * @author nulls.narik
 *
 */
abstract class AbstractAccount implements Account {
	private final static String MESSAGE_ERROR_BALANCE = "Balance less zero";

	protected final static String MESSAGE_ERROR_ARGUMENT = "Error argument, less zero";
			
	protected double balance;
	
	public AbstractAccount(double balance) throws IllegalArgumentException {
		if (balance < 0) {
			throw new IllegalArgumentException(MESSAGE_ERROR_BALANCE);
		}
		this.balance = balance;
	}
	
	public double getBalance() {
		return balance;
	}
	
	public void deposit(double x) throws IllegalArgumentException {
		if (x < 0) {
			throw new IllegalArgumentException(MESSAGE_ERROR_ARGUMENT);
		}
		balance += x;
	}
	
	public void withdraw(double x) throws IllegalArgumentException, NotEnoughFundsException {
		if (x < 0) {
			throw new IllegalArgumentException(MESSAGE_ERROR_ARGUMENT);
		}
		if (balance < x) {
			throw new NotEnoughFundsException();
		}
		
		balance -= x;
	}
	
	public double maximumAmountToWithdraw() {
		return balance;
	}
}
